package com.yizhi.student.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yizhi.common.utils.PageUtils;
import com.yizhi.common.utils.ShiroUtils;
import io.swagger.models.auth.In;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.yizhi.student.dao.StudentInfoDao;
import com.yizhi.student.domain.StudentInfoDO;
import com.yizhi.student.service.StudentInfoService;



@Service
public class StudentInfoServiceImpl implements StudentInfoService {



	@Autowired
	private StudentInfoDao studentInfoDao;

	@Override
	public StudentInfoDO get(Integer id){
		System.out.println("======service层中传递过来的id参数是：" + id + "======");
		return studentInfoDao.get(id);
	}


	@Override
	public PageUtils list(Map<String, Object> map){
		Integer currPage = Integer.parseInt((String) map.get("currPage"));
		Integer pageSize = Integer.parseInt((String) map.get("pageSize"));

		PageHelper.startPage(currPage,pageSize);
		List<StudentInfoDO> studentInfoDOList = studentInfoDao.list(map);
		PageInfo<StudentInfoDO> pageInfo = new PageInfo<>(studentInfoDOList);

		return new PageUtils(pageInfo.getList(),new Long(pageInfo.getTotal()).intValue());
	}

	//"===================================================================================="


	@Override
	public int count(Map<String, Object> map){
		return studentInfoDao.count(map);
	}

	@Override
	public int save(StudentInfoDO studentInfo){
		Date date = new Date();
		studentInfo.setAddUserid(new Long(ShiroUtils.getUserId()).intValue());
		studentInfo.setEditUserid(new Long(ShiroUtils.getUserId()).intValue());
		studentInfo.setAddTime(date);
		studentInfo.setEditTime(date);

		return studentInfoDao.save(studentInfo);
	}

	@Override
	public int update(StudentInfoDO studentInfo){
		studentInfo.setEditTime(new Date());
		studentInfo.setEditUserid(new Long(ShiroUtils.getUserId()).intValue());
		return studentInfoDao.update(studentInfo);
	}

	@Override
	public int remove(Integer id){
		return studentInfoDao.remove(id);
	}

	@Override
	public int batchRemove(Integer[] ids){
		return studentInfoDao.batchRemove(ids);
	}

}
